<template>
  <el-row type="flex" class="row-bg" justify="center">
    <el-col :xl="6" :lg="7">
      <h2>中港腾飞管理系统</h2>
      <el-image :src="require('@/assets/logo.png')" style="height: 160px;width: 350px; margin-top: 30px;  border-radius: 20px; "></el-image>
    </el-col>
    <el-col :span="1">
      <el-divider direction="vertical"></el-divider>
    </el-col>
    <el-col :xl="6" :lg="7">
      <el-form :model="loginForm" :rules="rules" ref="loginForm" label-width="100px" class="demo-loginForm">
        <el-form-item label="用户名" prop="username" style="width: 380px;">
          <el-input v-model="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password" style="width: 380px; letter-spacing: 5px;">
          <el-input v-model="loginForm.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :plain="true" @click="submitForm(loginForm)">登录</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>
<script>
import axios from "axios"; 
export default {
  name: "Login",
  data() {
    return {
      loginForm: { username: '', password: '', code: '', token: '' },
      // 表单验证规则
      rules: {
        username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
      },
      captchaImg: null
    };
  },
  methods: {
    submitForm(loginForm) {
      var that = this
      axios.post('http://localhost:8000/login',{
        username:loginForm.username,
           userpassword: loginForm.password
           }).then(function (res) {
             if(res.data.code == 1){
                   that.$message({ message: '恭喜你，登录成功', type: 'success'});
                    window.location.href = "http://localhost:8080/sys/index"
                    }else{
                       that.$message.error('账号或密码错误，请重新登录');
                    }
                })
    },
  },
  created() {
    this.getCaptcha()
  }
}
</script>

<style scoped>
  .el-row {
    background-color: rgb(153, 156, 151);
    height: 100%;
    display: flex;
    align-items: center;
    text-align: center;
  }
  .el-divider {
    height: 200px;
  }

  .captchaImg {
    float: left;
    margin-left: 8px;
    border-radius: 4px;
  }
   .el-form-item__label {
     color: #000;
   }

</style>